package com.byzoro.mapper;

import com.byzoro.pojo.Models;
import com.byzoro.pojo.Users;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface UsersMapper {
    @Select("select * from users where name = #{name} limit 1")
    Users getUserByName (@Param("name") String name);

    @Select("select * from users limit #{offset}, #{limit}")
    List<Users> list (@Param("offset") int offset, @Param("limit") int limit);

    @Select("select count(id) as count from users")
    int count ();

    @Select("select * from users where id = #{id} limit 1")
    Users getUserById (@Param("id") int id);

    @Insert("insert into users (name, password, created_at, last_login_time, head_pic) values (#{name},#{password},#{createdAt},#{lastLoginTime},#{headPic})")
    int create(Users users);

//    @Update("update users set name = #{name}, password = #{password}, head_pic = #{headPic} where id = #{id}")
    int update(Users users);

    @Delete("delete from users where id = #{id}")
    int delete(@Param("id") int id);

    @Update("update users set last_login_time = #{lastLoginTime} where name = #{name}")
    int updateLastLoginTimeByName(@Param("name") String name, String lastLoginTime);
}
